<?php
Class Codeigniter extends CI_Controller {
	
	function listtop(){
		$data['title']='hello,this is my firstpage';
		$this->load->model('get_db');
				
		$data['result']= $this->get_db->getAll();
		
		$this->load->view('listtop',$data);
	}
	
	function update(){
		$name = $this->input->post("name");
		$score = $this->input->post("score");
		
		$this->load->model('get_db');
		$data =array(
			'name'  =>$name,
			'point' =>$score
			);
			
		if ($this->get_db->check_exists($name)){
			
			$this->get_db->update($data,$name);
			
		}else{
			$count_row = $this->get_db->count_all();
			
			if ($count_row < 10){
				$this->get_db->insert($data);
			}else{
				$this->get_db->insert($data);
				$this->get_db->delete_min();	
				
			}
		}
		
		
		$arr = array(
			'status' => "sucess",
			'listtop10' =>$this->get_db->getAll()
		);
		
		echo json_encode($arr);
		
	}
} 

?>